package cn.itcast.jk.service.impl;

import cn.itcast.jk.dao.ExtCproductDao;
import cn.itcast.jk.dao.SysCodeDao;
import cn.itcast.jk.domain.ExtCproduct;
import cn.itcast.jk.domain.SysCode;
import cn.itcast.jk.pagination.Page;
import cn.itcast.jk.service.ExtCproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class ExtCproductServiceImpl implements ExtCproductService {
    @Autowired
    ExtCproductDao extCproductDao;
    @Autowired
    SysCodeDao sysCodeDao;
    @Override
    public List<ExtCproduct> findPage(Page page) {
        return null;
    }

    @Override
    public List<ExtCproduct> find(Map paraMap) {
        return extCproductDao.find(paraMap);
    }

    @Override
    public ExtCproduct get(Serializable id) {
        return extCproductDao.get(id);
    }

    @Override
    public void insert(ExtCproduct extCproduct) {
        extCproduct.setId(UUID.randomUUID().toString());        //设置UUID
        extCproduct.setAmount(extCproduct.getPrice()*extCproduct.getCnumber());     //计算总金额
        extCproductDao.insert(extCproduct);
    }

    @Override
    public void update(ExtCproduct extCproduct) {
        extCproduct.setAmount(extCproduct.getPrice()*extCproduct.getCnumber());     //计算总金额
        extCproductDao.update(extCproduct);
    }

    @Override
    public void deleteById(Serializable id) {
        extCproductDao.deleteById(id);
    }

    @Override
    public void delete(Serializable[] ids) {
        extCproductDao.delete(ids);
    }

    @Override
    public List<SysCode> getCtype() {
        Map map = new HashMap();
        map.put("parentId","0104");     //附件类型：0104
        return sysCodeDao.find(map);
    }
}
